//
//  HOTCloseDownDetailCell.m
//  Genpara
//
//  Created by AndyChang.zhang on 14-9-11.
//  Copyright (c) 2014年 zhangchh. All rights reserved.
//

#import "HOTCloseDownDetailCell.h"
#import "ZZZUILabel+Extend.h"

@implementation HOTCloseDownDetailCell

- (void)awakeFromNib
{
//    for (UIView *subView in self.subviews) {
//        
//        if ([subView isKindOfClass:NSClassFromString(@"UITableViewCellScrollView")]) {
//            
//            //((UIScrollView *)subView).delaysContentTouches = NO;
//        }
//    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

-(void)setData:(NSString *)seriaNum
          name:(NSString *)name
      dateTime:(NSString *)dateTime
       content:(NSString *)content
       emotion:(NSString *)emotion
    {
    
    self.nameLabel.text = name;
    self.serialNumLabel.text = seriaNum;
    self.dateTimeLabel.text = dateTime;
    self.contentLabel.text = content;
        self.emotion = emotion;
        
        
        
        if (![emotion isEqualToString:@"0"]) {
            
            //有图片
            for (NSLayoutConstraint *con in self.emojiImageView.constraints) {
                
                if (con.firstItem == self.emojiImageView && con.firstAttribute == NSLayoutAttributeHeight) {
                    
                    if ([emotion isEqualToString:@"1"]) {
                        self.emojiImageView.image = [UIImage imageNamed:@"stamp_kaese"];
                    } else if ([emotion isEqualToString:@"2"]){
                        self.emojiImageView.image = [UIImage imageNamed:@"stamp_orin"];
                    }
                    
                    con.constant = 108;
                }
            }
            
        } else {
            
            for (NSLayoutConstraint *con in self.emojiImageView.constraints) {
                
                if (con.firstItem == self.emojiImageView && con.firstAttribute == NSLayoutAttributeHeight) {
                    
                    self.emojiImageView.image = nil;
                    con.constant = 0;
                }
            }
        }
    
    //[self resizeView];

}



//-(float)getCellHeightWithContent:(NSString *)content {
//    
//    self.contentLabel.text = content;
//    
//    CGRect rect = [self.contentLabel fitBounding];
//    
//    float labHeight = rect.size.height;
//    labHeight = labHeight < 25 ? 25 : labHeight;
//    
//    return labHeight +
//    _quotationImageView.frame.size.height  //下引号的高度
//    +2 // 下引号与bgView的padding高度
//    +1; //分割线的高度
//}

-(void)resizeView {
    
    //self.contentLabel.text = content;
    CGRect rect = [self.serialNumLabel boundingWithSize:CGSizeMake(320, MAXFLOAT) stringAttr:@{NSFontAttributeName: self.serialNumLabel.font}];
    self.serialNumLabel.frame = CGRectMake(self.serialNumLabel.frame.origin.x, self.serialNumLabel.frame.origin.y, rect.size.width, self.serialNumLabel.frame.size.height);
    
    rect = [self.nameLabel boundingWithSize:CGSizeMake(320, MAXFLOAT) stringAttr:@{NSFontAttributeName: self.nameLabel.font}];
    self.nameLabel.frame = CGRectMake(ZZZ_calcX(self.serialNumLabel, 8), self.nameLabel.frame.origin.y, rect.size.width > 170 ? 170: rect.size.width, self.nameLabel.frame.size.height);
    
    rect = [self.dateTimeLabel boundingWithSize:CGSizeMake(320, MAXFLOAT) stringAttr:@{NSFontAttributeName: self.dateTimeLabel.font}];
    self.dateTimeLabel.frame = CGRectMake(ZZZ_calcX(self.nameLabel, 8), self.dateTimeLabel.frame.origin.y, rect.size.width, self.dateTimeLabel.frame.size.height);
    
    
    rect = [self.contentLabel fitBounding];
    
    float labHeight = rect.size.height;
    labHeight = labHeight < 25 ? 25 : labHeight;
    
    
    self.contentLabel.frame = CGRectMake(self.contentLabel.frame.origin.x, self.contentLabel.frame.origin.y, self.contentLabel.frame.size.width, labHeight);

    self.bgView.frame = CGRectMake(self.bgView.frame.origin.x, self.bgView.frame.origin.y, self.bgView.frame.size.width, self.contentLabel.frame.origin.y + labHeight + 10);

    _quotationImageView.frame = CGRectMake(_quotationImageView.frame.origin.x, self.bgView.frame.size.height - _quotationImageView.frame.size.height - 2,  _quotationImageView.frame.size.width, _quotationImageView.frame.size.height);
    
    self.frame = CGRectMake(self.frame.origin.x, self.frame.origin.y, self.frame.size.width, self.bgView.frame.size.height +1);
    
    self.contentView.frame = CGRectMake(self.contentView.frame.origin.x, self.contentView.frame.origin.y, self.contentView.frame.size.width, self.bgView.frame.size.height);
}

@end
